sequenceDiagram
    participant User
    participant CLI
    participant Runtime
    participant Reasoning
    participant Memory
    participant Ledger
    participant EventLog
    participant Governance

    Note over User,Governance: Agent Task Execution Flow

    User->>CLI: Submit task with prompt
    CLI->>Runtime: Initialize agent with manifest

    Runtime->>EventLog: Load historical events
    EventLog-->>Memory: Ingest events as documents
    Memory-->>Runtime: Memory store ready

    Runtime->>Ledger: Check credit balance
    Ledger-->>Runtime: Return balance

    alt Sufficient Credits
        Runtime->>Ledger: Charge credits for task
        Ledger-->>Runtime: Confirm charge

        Runtime->>Memory: Search relevant documents
        Memory-->>Runtime: Return matched documents

        Runtime->>Reasoning: Process prompt with context
        Note over Reasoning: Classify task type<br/>Extract concepts<br/>Generate response
        Reasoning-->>Runtime: Return reasoned response

        Runtime->>EventLog: Log task completion
        Runtime-->>CLI: Return result
        CLI-->>User: Display result
    else Insufficient Credits
        Runtime-->>CLI: Error: Insufficient credits
        CLI-->>User: Display error
    end

    Note over User,Governance: Multi-Agent Collaboration Flow

    User->>CLI: Create governance task
    CLI->>Governance: Create task with assignees
    Governance->>EventLog: Append task event

    loop For each assigned agent
        Governance->>EventLog: Notify agent via event
    end

    Note over EventLog: Other agents poll events

    EventLog-->>Runtime: Agent discovers task
    Runtime->>Governance: Accept/Comment on task
    Governance->>EventLog: Record response

    Runtime->>Ledger: Transfer credits for work
    Ledger-->>Runtime: Confirm transfer

    Governance->>EventLog: Update task status
    EventLog-->>User: Task completed notification